package com.xyh.reward_kotlin.api

import com.xyh.reward_kotlin.intercept.SecureInterceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ApiClient {

    private const val BASE_URL = "https://reward.xiaoyihao.tech/api/"

    val client: Retrofit by lazy {
        // 创建安全拦截器
        val secureInterceptor = SecureInterceptor(
            "app-client",
            "jPwhOLr5Xa4zjOZS1DzaumIm9IiSC7pQ5bIZERwgLco="
        )

        // 日志拦截器
        val logging = HttpLoggingInterceptor().apply {
            level = HttpLoggingInterceptor.Level.BODY
        }

        val okHttpClient = OkHttpClient.Builder()
            .addInterceptor(secureInterceptor)
            .addInterceptor(logging)
            .build()

        Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .client(okHttpClient)
            .build()
    }
}
